/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.ujf.sharepas.impl;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import edu.ujf.sharepas.impl.Constante.CategoryType;

/**
 *
 * @author yaiba
 */
public class Library implements Serializable{

	/**
	 * create a library associated to the file
	 * @param libFile
	 */
	private List<Category> listCategory = null;
	
	private User owner = null;
	
	private int compteur = 1;
	
	public void setOwner(User u){
		this.owner = u;
	}
	
	public int getCompteur(){
		return this.compteur;
	}
	
	public void setCompteur(int compteur){
		this.compteur =compteur;
	}
	public User getOwner(){
		return this.owner;
	}
	
	public Library(User owner, File avFile){
		listCategory = new ArrayList<Category>();
		listCategory.add(new Category("Video",0));
		listCategory.add(new Category("Audio",1));
		listCategory.add(new Category("Photo",2));
		listCategory.add(new Category("Doc",3));
	}
	public Library(){
		listCategory = new ArrayList<Category>();
		listCategory.add(new Category("Video",0));
		listCategory.add(new Category("Audio",1));
		listCategory.add(new Category("Photo",2));
		listCategory.add(new Category("Doc",3));
	}
	
	public ShareFile getShareFile(String name){
		ShareFile find = null;
		for(int i=0;i< this.getAllFile().size()&& find == null;i++){
			ShareFile s = this.getAllFile().get(i);
			if( s.getIFile().getName().equalsIgnoreCase(name) ){
				find = s;
			}
		}
		return find;
	}
	
	public Library(User owner){
		listCategory = new ArrayList<Category>();
	}
	
	public List<Category> getListCategory(){
		return listCategory;
	}
	
	public Category getCategory(Constante.CategoryType category){
		int i=0;
		int k=0;
		for( Category c:this.listCategory){
			if( c.getType() ==  category.toInt()){
				i = k;
			}
			k++;
		}
		return listCategory.get(i);
	}
	
	public Category addCategory(int type){
		String name = "";
		if( type == Constante.CategoryType.AUDIO.toInt()){
			name = "Audio";
		}else if( Constante.CategoryType.VIDEO.toInt() == type ){
			name = "Video";
		}else if( Constante.CategoryType.PHOTO.toInt() == type ){
			name = "Photo";
		}else if( Constante.CategoryType.DOC.toInt() == type ){
			name = "Doc";
		}
		Category c = new Category(name,type);
		this.listCategory.add(c);
		return c;
	}
	
	public void addShareFile(ShareFile c , CategoryType c2){
		Category cat = this.getCategory(c2);
		cat.addShareFile(c);
	}
	public List<ShareFile> getAllFile(){
		return null;
	}


	
	
}
